package com.zc.initConstructor;

import com.zc.dao.NavMapper;
import com.zc.entity.Nav;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 方法1:项目启动时初始化执行内容体
 */
@Component
public class Obser implements ApplicationListener<ContextRefreshedEvent> {
    @Resource
    private NavMapper navDao;

    public static final Map<Integer, Nav> roleNav = new HashMap<>();

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
//        List<Nav> list = navDao.findAll();
//        if (list != null) {
//            for (Nav nav : list) {
//                roleNav.put(nav.getId(), nav);
//            }
//        }
//
//        if (event.getApplicationContext().getParent() == null) {
//            TimerTask task = new TimerTask() {
//                @Override
//                public void run() {
//                    ThreadA a = new ThreadA();
//                    a.start();
//                    while (a.isFlag()) {
//                        System.out.println(a.getI() + "::" + a.isFlag());
//                        if (a.getI() > 10) {
//                            a.setFlag(false);
//                        }
//                        try {
//                            Thread.sleep(1500);
//                        } catch (InterruptedException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                }
//            };
//            //通过timer 新建一个定时器来加载线程
//            Timer timer = new Timer();
//            timer.schedule(task, 4000);
        }
    }



